package com.tebiecloud.order.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tebiecloud.order.client.model.entity.OrderGoods;
import com.tebiecloud.order.server.mapper.OrderGoodsMapper;
import com.tebiecloud.order.server.service.OrderGoodsService;
import com.tebiecloud.common.mybatis.base.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 订单商品信息 服务实现类
 * @author tebie
 * @date 2019-09-15
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OrderGoodsServiceImpl extends BaseServiceImpl<OrderGoodsMapper, OrderGoods> implements OrderGoodsService {

    @Override
    public List<OrderGoods> listByOrderId(Long orderId,Long userId) {
        QueryWrapper<OrderGoods> queryWrapper = new QueryWrapper<>();
        if(orderId != null){
            queryWrapper.eq("order_id", orderId);
        }
        if(userId != null){
            queryWrapper.eq("user_id", userId);
            queryWrapper.gt("remain_write_off_times",0);
        }
        queryWrapper.orderByDesc("ct");
        return super.list(queryWrapper);
    }
}
